//
//  AY_BookVpItemCell.m
//  AiYue
//
//  Created by boWen on 2023/10/26.
//

#import "AY_BookVpItemCell.h"

@interface AY_BookVpItemCell ()
@property (nonatomic,strong) UIView * bg_View;//底部圆角
@property (strong,nonatomic) UIImageView *tipsImageView;
@property (strong,nonatomic) UILabel *tipsLabel;
@property (strong,nonatomic) UILabel *topTitleLabel;
@property (strong,nonatomic) UILabel *midTitleLabel;
@property (strong,nonatomic) UILabel *bottomTitleLabel;

@end

@implementation AY_BookVpItemCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:COLOR(@"#F7F5F6") andRadius:YNUM(6) andAddSubView:self.contentView];
        [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.equalTo(self.contentView);
        }];
        
        self.tipsImageView = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:THEME_COLOR andRadius:1 andAddSubView:self.contentView];
        [self.tipsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView);
            make.top.equalTo(self.contentView).offset(YNUM(-10));
            make.height.mas_offset(YNUM(25));
            make.width.mas_offset(YNUM(52));
        }];
                
        self.tipsLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:[UIColor whiteColor] andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.tipsImageView];
        self.tipsLabel.textAlignment = NSTextAlignmentCenter;
        [self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.left.bottom.equalTo(self.tipsImageView);
        }];
        
        self.topTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#010101") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(15)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
        self.topTitleLabel.textAlignment = NSTextAlignmentCenter;
        [self.topTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bg_View).offset(YNUM(30));
            make.left.equalTo(self.bg_View).offset(YNUM(5));
            make.right.equalTo(self.bg_View).offset(YNUM(-5));
        }];
        
        self.midTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#814b1d") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(24)] andLines:2 andRadius:0 andAddSubView:self.contentView];
        [self.midTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topTitleLabel.mas_bottom).offset(YNUM(5));
            make.centerX.equalTo(self.bg_View);
        }];
        
        self.bottomTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#999999") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.contentView];
        self.bottomTitleLabel.textAlignment = NSTextAlignmentCenter;
        [self.bottomTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.midTitleLabel.mas_bottom).offset(YNUM(10));
            make.left.equalTo(self.bg_View).offset(YNUM(5));
            make.right.equalTo(self.bg_View).offset(YNUM(-5));
        }];
        
    }
    return self;
}



- (void)setVpSubModel:(VpProductModel *)vpSubModel {
    _vpSubModel = vpSubModel;
    
    if ([vpSubModel.isSel isEqual:@"1"]) {
        self.topTitleLabel.textColor = COLOR(@"814b1d");
        self.midTitleLabel.textColor = COLOR(@"814b1d");
        self.bottomTitleLabel.textColor = COLOR(@"814b1d");
        self.bg_View.layer.borderWidth = 2.0f;
        self.bg_View.layer.borderColor = COLOR(@"#f5db97").CGColor;
        self.bg_View.backgroundColor = COLOR(@"#fffaec");
    }else {
        self.topTitleLabel.textColor = COLOR(@"010101");
        self.bottomTitleLabel.textColor = COLOR(@"999999");
        self.midTitleLabel.textColor = COLOR(@"010101");
        self.bg_View.layer.borderWidth = 2.0f;
        self.bg_View.layer.borderColor = COLOR(@"#e7e7e7").CGColor;
        self.bg_View.backgroundColor = COLOR(@"#F7F5F6");
    }
    
    self.tipsLabel.text = kStringUtils(_vpSubModel.tipStr);
    self.tipsImageView.hidden = kStringIsEmpty(_vpSubModel.tipStr);
    
    if (!kStringIsEmpty(_vpSubModel.tipStr)) {
        [self.tipsImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(YNUM(_vpSubModel.tipStr.length*15));
        }];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, YNUM(_vpSubModel.tipStr.length*15), YNUM(25)) byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(YNUM(16), YNUM(16))];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.tipsImageView.bounds;
        maskLayer.path = maskPath.CGPath;
        self.tipsImageView.layer.mask = maskLayer;
    }
    
    self.topTitleLabel.text = kStringUtils(_vpSubModel.productName);
    self.midTitleLabel.text = [NSString stringWithFormat:@"￥%@", kStringUtils(_vpSubModel.price)];
    NSString *labelText = self.midTitleLabel.text;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSRange rangeA = [labelText rangeOfString:@"￥"];
    [attributedString addAttribute:NSFontAttributeName value:YFont(12) range:rangeA];
    self.midTitleLabel.attributedText = attributedString;
    
    self.bottomTitleLabel.text = [NSString stringWithFormat:@"原价%@", kStringUtils(_vpSubModel.oriPrice)];
    if (self.bottomTitleLabel.text.length > 0) {
        NSString *labelText1 = self.bottomTitleLabel.text;
        NSMutableAttributedString *attributedString1 = [[NSMutableAttributedString alloc] initWithString:labelText1];
        NSRange rangeB = [labelText1 rangeOfString:labelText1];
        [attributedString1 addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:rangeB];//删除线
        if ([vpSubModel.isSel isEqual:@"1"]) {
            [attributedString1 addAttribute:NSStrikethroughColorAttributeName value:COLOR(@"#814b1d") range:rangeB];//删除线色
        }else {
            [attributedString1 addAttribute:NSStrikethroughColorAttributeName value:COLOR(@"#999999") range:rangeB];//删除线色
        }
        
        self.bottomTitleLabel.attributedText = attributedString1;
    }
}




@end
